package com.jianyun.jyzs.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.jianyun.jyzs.R;

import java.util.List;

import com.jianyun.jyzs.utils.RceLog;

/**
 * Created by mlli on 2017/11/8.
 */

public class StringAdapter extends RecyclerView.Adapter{
    private Context context;
    private List<String> list;

    public StringAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public List<String> getList() {
        return list;
    }

    public void setList(List<String> list) {
        RceLog.d("lml","notifyDataSetChanged");
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.left_textview, null);
        return new MHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        RceLog.d("lml","onBindViewHolder"+list.get(position));
        MHolder mHolder = (MHolder) holder;
        mHolder.tv.setText(list.get(position));

    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }
    class MHolder extends RecyclerView.ViewHolder{

        private final TextView tv;

        public MHolder(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.title);
        }
    }
}
